package com.xlsx.utils;

import cn.hutool.core.io.FileUtil;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class WriteStringBufferToTxt {
    public static void writeToTxtFile(StringBuffer stringBuffer,String tableName) {
        // 获取当前时间并格式化
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        SimpleDateFormat sdf = new SimpleDateFormat("HHmmss");
        String currentTime = sdf.format(new Date());

        String path = DownTemp.path();

        try (BufferedWriter writer = new BufferedWriter(new FileWriter(path + tableName + "_" + currentTime + ".txt"))) {
            writer.write(stringBuffer.toString());
            System.out.println("建表语句文件路径:"+path + tableName + "_" + currentTime + ".txt");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
